package top.gytf.unifiedcall.common.contract;

import lombok.Getter;
import top.gytf.distools.lifecycle.AbstractLifecycle;
import top.gytf.unifiedcall.model.contract.ApiContract;

import java.lang.reflect.Method;
import java.util.List;

/**
 * 实现公用逻辑的API协定读取
 */
@Getter
public abstract class AbstractApiContractReader extends AbstractLifecycle implements ApiContractReader {
    protected abstract List<ApiContract> doRead(Method apiMethod);

    @Override
    public final List<ApiContract> read(Method apiMethod) {
        assertReady();

        List<ApiContract> apiContracts = doRead(apiMethod);
        apiContracts.forEach(ApiContract::validate);
        return apiContracts;
    }
}
